﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Appraisal_System.Utility;
using System.Data.SqlClient;

namespace Appraisal_System.Models
{
   public  class AppraisalBases
    {
        public int Id { get; set; }
        public String BaseType { get; set; }
        public int AppraisalBase { get; set; }
        public bool IsDel { get; set; }


        //摘要：
        //      整表的数据
        //

        public static List<AppraisalBases> ListAll()
        {
            List<AppraisalBases> appraisalBases = new List<AppraisalBases>();
;            //查询数据
            DataTable dt  = SqlHelper.ExecuteTable("SELECT * FROM AppraisalBases ");

            foreach (DataRow dr in dt.Rows)
            {
                appraisalBases.Add(ToModel(dr));
            }
            return appraisalBases;
        }
        private static AppraisalBases ToModel(DataRow dr)
        {
            AppraisalBases appraisalBase = new AppraisalBases();
            appraisalBase.Id = (int)dr["Id"];
            appraisalBase.BaseType = dr["BaseType"].ToString();
            appraisalBase.AppraisalBase =(int) dr["AppraisalBase"];
            appraisalBase.IsDel = (bool)dr["IsDel"];
            return appraisalBase;
        }
        public static int Update(AppraisalBases appraisalBase)
        {
            return SqlHelper.ExecuteNonQuery($"UPDATE AppraisalBases SET BaseType=@BaseType,AppraisalBase=@AppraisalBase,IsDel=@IsDel WHERE Id=@Id",
                new SqlParameter("@Id", appraisalBase.Id),
                new SqlParameter("@BaseType", appraisalBase.BaseType),
                 new SqlParameter("@AppraisalBase", appraisalBase.AppraisalBase),
                new SqlParameter("@IsDel", appraisalBase.IsDel));
        }
    }
}
